<template>
	<view>
		<view class="load" v-if="!load">
			<view style="text-align: center;">正在加载...</view>
			<!-- <u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon> -->
		</view>
		<view class="assistant" v-else>
			<view class="fixfix">
				<view class="fix" id="fix">
					<top-status></top-status>
					<!-- <view class="logo">
						<image src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1731664251564468.png" mode="widthFix"></image>
					</view> -->
					<view class="tabs wap" v-if="!showSearch">
						<view class="tab5" @click="showSearch = true">
							<uni-icons type="search" size="24" color="#333333"></uni-icons>
						</view>
						<view class="tagbox">
							<view class="tab3 tab_horn" :class="{ 'tab4': tabInd == item.id }" v-for="(item, index) in fixTab" :key="index" @click="tabEvent(item)">
								{{ item.name }}
								<view class="horn_mark" :class="getCount" v-if="item.name=='新人' && count">
									{{count}}
								</view>
							</view>
						</view>
						<view class="checkbox" style="opacity: 0;" @click="toFiltrate">
							筛选
						</view>
					</view>
					<view class="tabssearch wap" v-if="showSearch">
						<u-search inputAlign="left" placeholder="搜索会员ID或昵称" @search="search()" v-model="Name"
							height="30" actionText="取消" :actionStyle="{ color: '#333333' }" @custom="celSearch"></u-search>
					</view>
					
					<view class="tab_body">
						<view class="tab_cell" :class="{'tab_active': tagindex == index }" v-for="(item,index) in componentList" :key="index" @click="chooseComponent(item, index)">
							<view class="icon" v-if="item.Icon">
								<image v-if="tagindex==index" :src="item.Nicon" mode="aspectFill"></image>
								<image v-else :src="item.Icon" mode="aspectFill"></image>
							</view>
							<view class="tab_tit">
								{{item.Tag}}
							</view>
						</view>
					</view>
					
				</view>
			</view>
			<x-scroll @scroll="scroll" :fixed="true" :isNav="true" @onRefresh="onRefresh" @scrolltolower="scrolltolower"
				:refresh="true" :offset="fix_height" extraheight="52">
				<view class="message_box" v-if="MsgNum > 0" @click="tab_to('/pages/tab/msg')">
					<view class="item"> 有{{ MsgNum }}条消息</view>
				</view>
				<!-- <view class="user_status_box" v-if="is_show_app_tips">
					<view class="item"> <text @click="nav_to('/pages/user/apply_member')">动魅会员特权及优惠介绍</text>
						<image class="close" @click="close_app_tips()" style="width:32rpx;"
							src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1719917012240382.png"
							mode="widthFix"></image>
					</view>
				</view> -->
				<view class="user_status_box" v-if="auth == 0">
					<view class="item"> <text @click="gotostart()">马上注册领取7天会员~</text>
						<image class="close" @click="closeVip()" style="width:32rpx;"
							src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1719917012240382.png"
							mode="widthFix"></image>
					</view>
				</view>
				<view v-if="list.length > 0" class="list wap">
					<block v-for="(item) in list" :key="item.ID">
						<view class="item" @click="nav_to(`/pages/user/user_visitor?id=${item.ID}`)">
							<view class="top">
								<view class="tagbox">
									<!-- <view class="tagcolor2" v-if="item.Level == '教练'">教练</view> -->
									<!-- <view class="tagcolor2">教练</view> -->
									<!-- <view class="tagcolor2" v-if="item.Level == '星助教'">星助教</view> -->
								</view>
								<view class="imgbox">
									<image :src="item.UserImgs + '?x-oss-process=image/resize,m_fill,w_700'"
										mode="aspectFill" />
									<view class="tag_body" v-if="item.Tag">
										<block  v-for="(el,i) in item.Tag" :key="i">
											<view class="tag_cell" v-if="i<3">
												{{el}}
											</view>
										</block>
										
									</view>
									<view class="top_bottom">
										<view class="memberInfo" v-if="false">
											<view class="name u-line-1">
												{{ item.Name ? $util.entitiesToUtf16(item.Name) : '' }}
											</view>
											<view class="member member_hei_vip" v-if="item.UserType == '黑金年卡会员'">黑金年卡</view>
											<view class="member member_hei" v-if="item.UserType == '年卡会员'">年卡</view>
											<view class="member number_huan" v-if="item.UserType == '金卡会员'">金卡</view>
											<view class="member number_huan" v-if="item.UserType == '月卡会员'">月卡</view>
											<view class="member number_huan" v-if="item.UserType == '体验会员'">体验金卡</view>
											<!-- <view class="member_wealth" v-if="item.MemberWealth.WealthLevel > 0">
												LV{{ item.MemberWealth.WealthLevel }}</view> -->
											
										</view>
										
										<view class="memberInfo2">
											<view class="bottom_info" v-if="false">
												<text v-if="item.Birthday">{{ getYearStr(item.Birthday) }}后</text>
												<text>{{ item.City ? item.City : '' }}</text>
												<text
													v-if="item.Birthday && constellate(item.Birthday)">{{ constellate(item.Birthday).Name }}</text>
											</view>
											<view class="flx">
												<view class="wx">
													<uni-icons type="weixin" size="18" color="#42c444"></uni-icons>
													<text>{{ item.WechatNo }}</text>
												</view>
												<view class="distance" v-if="item.Distance">
													<view class="icon">
														<image src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1733477511719543.png" mode="aspectFill"></image>
													</view>
													<text>{{ item.Distance > 100 ? '>100' : parseFloat(item.Distance).toFixed(1) }}km</text>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view class="online">{{ getTime(item.UpdateTime) }}</view>
								
								<view class="uinfo_body">
									<view class="uinfo_cell">
										<view class="uinfo_head">
											<image :src="item.HeadImgUrl ? item.HeadImgUrl:item.UserImgs" mode="aspectFill"></image>
										</view>
										<view class="uinfo_box">
											<view class="box_tit">
												<view class="tit_name">
													{{ item.Name ? $util.entitiesToUtf16(item.Name) : '' }}
												</view>
												<view class="member member_hei_vip" v-if="item.UserType == '黑金年卡会员'">黑金年卡</view>
												<view class="member member_hei" v-if="item.UserType == '年卡会员'">年卡</view>
												<view class="member number_huan" v-if="item.UserType == '金卡会员'">金卡</view>
												<view class="member number_huan" v-if="item.UserType == '月卡会员'">月卡</view>
												<view class="member number_huan" v-if="item.UserType == '体验会员'">体验金卡</view>
												<view class="tag_teacher" v-if="item.Level == '教练'">教练</view>
											</view>
											<view class="box_lit">
												<text v-if="item.Birthday">{{ getYearStr(item.Birthday) }}后{{' '}}</text>
												<text>{{ item.City ? item.City : '' }}{{' '}}</text>
												<text v-if="item.Birthday && constellate(item.Birthday)">{{ constellate(item.Birthday).Name }}</text>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>

					</block>
					<view style="height: 130rpx;margin-left: 400rpx;"></view>
				</view>
				<block v-else>
					<!-- <text>加载会员中...</text> -->
					<view class="loadbox" style="display: flex;flex-direction: column;justify-content: center;align-items: center;height: 50vh;">
						<image style="width: 128rpx;height:128rpx" src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17124806786111367.png">
						</image>
						<view style="color: #999999;">努力加载会员信息</view>
					</view>
				</block>
			</x-scroll>

			<!-- <view class="registerbox" v-if="auth == 0">
				<image class="regimg" src="https://appapi.wavestation.cn/Data/Img/default_head.png">
				</image>
				<view>
					<view class="regtitle_1">欢迎来到动魅</view>
					<view class="regtitle_2">赶紧注册来认识更多的玩家吧</view>
				</view>
				<view class="regbtn" @click="gotostart">注册领好礼</view>
			</view> -->
			<!-- 优惠卷弹窗 -->
			<view v-if="(iscoupon || isreceive) && couponlist.length > 0" class="couponbox">
				<view style="width: 90%;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%)">
					<image class="titleh1"
						src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1712889460150219.png"></image>
					<view class="coupon">
						<view class="title1">用户惊喜福利</view>
						<view v-if="couponlist.length > 0">
							<view class="conbox" v-for="(value, index) in couponlist" :key="index">
								<image class="conimg"
									src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17128895330751157.png">
								</image>
								<view>
									<view class="contitle_1">{{ value.Title }}</view>
									<view class="contitle_2">领取后30天内有效</view>
								</view>
								<view class="numbox">x1</view>
							</view>
						</view>
						<view @click="couponstate" class="nicebtn">开心收下</view>
					</view>
					<image @click="closecoupon" class="closeimg"
						src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1712889568739446.png"></image>
				</view>
			</view>
		</view>
		<view class="add_btn" v-if="tagtext!='全部'" @click="release">上传<br>{{tagtext}}<br>照片
		</view>
		<!-- 广告弹出层 -->
		<uni-popup ref="banner_ad" type="center">
			<view class="ad-popup" :style="{ width: ad_detail.Ad_Width + 'rpx', height: ad_detail.Ad_Height + 'rpx' }">
				<view class="popup-title">
					<view v-if="ad_detail.Close_Location == 'top-right'" class="popup-close"
						@click="$refs['banner_ad'].close()">关闭
					</view>
				</view>
				<image :src="ad_detail.Banner" mode="aspectFill" @click="go_ad_url(`${ad_detail.GoUrl}`)"></image>

				<view class="down-close" v-if="ad_detail.Close_Location == 'down'" @click="$refs['banner_ad'].close()">
					<uni-icons type="close" size="36" color="#fff"></uni-icons>
				</view>
			</view>
		</uni-popup>

		<!-- 会员到期窗口 -->
		<uni-popup ref="member_expired_pop" type="center">
			<view class="member-popup">
				<view class="popup-title">
					{{ IsExpiredUser.UserType }}到期通知
					<view class="popup-close" @click="$refs['member_expired_pop'].close()">X</view>
				</view>
				<view class="tips">{{ IsExpiredUser.Msg }}</view>
				<view class="desc">
					<view class="title">您即将失去以下权益：</view>
					<view class="txtbox">
						<view class="conbox" v-for="(item, index) in imglist" :key="index">
							<image class="conimg" :src="item.src"></image>
							<view class="context">{{ item.title }}</view>
						</view>
					</view>

				</view>

				<view class="pop_btn">
					<block v-if="IsExpiredUser.UserType == '年卡会员' || IsExpiredUser.UserType == '黑金年卡会员'">
						<view class="btn-upgrade" @click="expired_upgrade">赶快续期</view>
					</block>
					<block v-else>
						<view class="btn-upgrade" @click="expired_upgrade">开通会员</view>
					</block>
				</view>
				<view class="tips" v-if="show_close_expired_tips" @click="close_expired_tips">不再提示</view>
			</view>

		</uni-popup>
		<VipAlertVue></VipAlertVue>
	</view>
</template>

<script>
import topStatus from "@/components/topStatus/topStatus.vue";
import VipAlertVue from '../../components/VipAlert/VipAlert.vue';
export default {
	async created() {
		if (await this.$store.getters.getLoginState) {

		}
	},
	components: {
		topStatus,
		VipAlertVue
	},
	data() {
		return {
			tagindex: 0,
			tagtext: '',
			componentList: ['健身', '高尔夫', '运动', '羽毛球', '网球', '掼蛋'],
			fixTab:[
				{	name:'活跃',
					id:1
				},
				{	name:'新人',
					id:4
				},
				{	name:'附近',
					id:3
				},
			],
			stCompanyID: 6007,
			auth: 1,
			isreceive: false, // 是否领取
			iscoupon: false, // 注册优惠卷弹窗
			couponlist: [],
			tabInd: 1,
			longitude: null,
			latitude: null,

			showSearch: false,
			imgCurr: [],
			load: false,
			user: {},
			_freshing: true,
			list: [],
			PageIndex: 1,
			PageSize: 10,
			Name: "",

			Sex: "",
			UserType: "",
			GolfPoint: "",
			City: "",

			MsgNum: '',
			exposure_arr: new Set(), //曝光集合

			userList: [], //群成员列表
			conversationList: [], //会话列表
			groupList: [], //群聊列表
			sendUser: {},

			lastTime: 0,
			isRotated: false, //头像旋转
			idx: 0,

			ad_detail: {},
			msg_box: [],
			msg_index: 0,
			msg_item: {},

			newUserCount: 0,

			is_show_app_tips: true,

			IsExpiredUser: {},
			show_close_expired_tips: false,

			//人气榜
			pop_list: [],
			ossPath: '',

			imglist: [{
				src: this.$ossPath + '/upload/17110902548021395.png',
				title: '加好友'
			},
			{
				src: this.$ossPath + '/upload/17110903071131233.png',
				title: '加微信'
			},
			{
				src: this.$ossPath + '/upload/171109032005821.png',
				title: '优先推荐'
			}
			],
			fix_height:190,
			count:0
		}
	},
	computed: {
		getCount(){
			if(this.count>99 || this.count=='99+'){
				return 'num99'
			}
			if(this.count>=10){
				return 'num10'
			}
			return ''
		},
	},
	watch: {
		Sex(newVal) {
			this.PageIndex = 1
			this.init();
		},
		City(newVal) {
			this.PageIndex = 1
			this.init();
		},
	
		list(newVal) {
			newVal.forEach(item => {
				this.imgCurr.push(1);
			})
		},
		tabInd(newVal) {
			this.PageIndex = 1
			this.init();
		},
		showSearch(val){
			this.$nextTick(async () => {
				// await this.GetMemberTag()
				const height = await this.getHeight('#fix') //计算的元素高度
				this.fix_height = height //剩余屏幕高度
			})
		},
		load(val){
			this.$nextTick(async () => {
					await this.GetMemberTag()
					const height = await this.getHeight('#fix') //计算的元素高度
					console.log('=》》》》》》》》》》》》》》》》》》》》》》height',height);
					this.fix_height = height //剩余屏幕高度
			})
		}
	},
	
	async onLoad(e) {
		await this.GetMemberTag()
		this.reLoad()
		
	},
	onShow() {
		this.iscoupon = uni.getStorageSync('iscoupon') || false
		// this.isreceive = uni.getStorageSync('isreceive')
		this.getMsgNum();
		this.getList();
		this.totalNum()
		let that = this;
		that.stCompanyID = uni.getStorageSync('CompanyID') || 6007
		this.getMemberNum().then((latestCount) => {
			// 从本地存储中获取上次记录的消息数量
			const localCount = uni.getStorageSync('usersCount') || 0;
	
			that.toatalUserCount = latestCount;
			// 计算新消息数量
			that.newUserCount = latestCount - localCount;
	
		});
		this.auth = uni.getStorageSync('user').IsAuth
		this.$store.dispatch('getMyNum')
	},
	onReady() {
		setTimeout(()=>{
			this.$nextTick(async () => {
					await this.GetMemberTag()
					const height = await this.getHeight('#fix') //计算的元素高度
					console.log('=》》》》》》》》》》》》》》》》》》》》》》height',height);
					this.fix_height = height //剩余屏幕高度
			})
		},500)
		
	},
	onUnload() {
		uni.$off('getFiltrate')
	},
	methods: {
		getTag(Tag){
			if(Tag){
				if(Tag.includes(',')){
					return Tag.join(',')
				}else{
					return [Tag]
				}
			}else{
				return []
			}
		},
		async totalNum() {
			let res = await this.$api.post("/Member/TotalNum");
			const num = res.data || 0;
			const oldNum = uni.getStorageSync("usersCount") || 0;
			const newNum = num - oldNum;
			console.log('>>>>>>>}}}}}}}}}}}}}}}}}',num,oldNum,newNum);
			this.count = newNum < 0 ? 0 : newNum;
			// this.count = 100
			this.count = this.count > 99 ? '99+' : this.count
			uni.setStorageSync("usersCount", num);
		},
		tabEvent(item) {
			this.tabInd = item.id;
			console.log('》》》',item.id);
			if (this.tabInd === 4) this.count = 0;
		},
		getHeight(id) {
				return new Promise(resolve => {
						let query = uni.createSelectorQuery().in(this);
						query.select(id).boundingClientRect();
						query.exec((res) => {
								resolve(res[0].height)
						})
				})
		},
		//发布
		release() {
			let _this = this
			if (_this.user.IsAuth == 0) {
				uni.showModal({
					title: '温馨提示',
					content: '您还没注册，请先注册',
					confirmText: '确定',
					success: function (rs) {
						if (rs.confirm) {
							_this.nav_to('/pages/start/start2')
							return
						} else if (rs.cancel) {

						}
					}
				});
			} else {
				this.nav_to('/pages/user/user_sportimg')
			}

		},
		async GetMemberTag() {
			let res = await this.$api.post('Member/GetMemberTag', {
				PageIndex: 1,
				PageSize: 50
			});
			this.componentList = res.data || []
			if(Array.isArray(this.componentList) && this.componentList.length){
				this.componentList.unshift({
					Tag:'全部'
				})
				this.tagtext = this.componentList[0].Tag
			}
			// if (res.code == 0) {
			// 	if (res.data.length > 0) {
			// 		let list = []
			// 		for (let i = 0; i < res.data.length; i++) {
			// 			list.push(res.data[i].Tag)
			// 		}
			// 		this.componentList = list
			// 	}
			// }
		},
		// 点击选择运动
		chooseComponent(item, index) {
			this.tagindex = index
			this.tagtext = item.Tag
			// if(this.tagindex==index){
			// 	this.tagindex = -1
			// 	this.tagtext = ''
			// }else{
			// 	this.tagindex = index
			// 	this.tagtext = item.Tag
			// }
			
			this.PageIndex = 1;
			this.list = [];
			this.getList()

		},



		//优惠卷弹窗状态
		//领取
		couponstate() {
			// this.iscoupon = false
			this.isreceive = false
			uni.setStorageSync('iscoupon', false);
			uni.setStorageSync('isreceive', this.isreceive);
			this.nav_to('/pages/court/mycoupon?tabInd=' + 1);
		},
		closecoupon() {
			this.iscoupon = false
			this.isreceive = false
			uni.setStorageSync('iscoupon', false);
			uni.setStorageSync('isreceive', true);
		},
		//底部注册
		gotostart() {
			this.nav_to('/pages/start/start2');

		},
		closeVip(){
			this.auth = 1
			console.log(this.auth);
		},
		async getIsExpiredUser() {
			if (uni.getStorageSync('user_expired_tips_num') > 5) {
				//当提示弹窗大于9次之后出现 “不再提示”的按钮
				this.show_close_expired_tips = true;
			}

			if (uni.getStorageSync('user_expired_tips_num') < 9999) {
				//判断用户是否到期
				let res = await this.$api.post('User/IsExpiredUser');

				if (res.data) {
					this.IsExpiredUser = res.data;
					if (this.IsExpiredUser.IsExpired) {
						this.$refs.member_expired_pop.open();
					}

					let n = uni.getStorageSync('user_expired_tips_num');
					uni.setStorageSync('user_expired_tips_num', n + 1);
				}
			}
		},
		expired_upgrade() {
			this.nav_to('/pages/user/apply_member');
			this.$refs.member_expired_pop.close();
		},
		close_expired_tips() {
			uni.setStorageSync('user_expired_tips_num', 9999);

			this.$refs.member_expired_pop.close();
		},
		async saveCid() {
			// #ifdef APP
			plus.runtime.setBadgeNumber(0);
			uni.getPushClientId({
				success: (res) => {
					console.log(res);
					this.$api.post('/User/BindCID', {
						CID: res.cid
					});
				},
				fail(err) {
					console.log(err)
				}
			})
			// #endif
		},
		close_app_tips() {

			uni.setStorageSync('show_member_tips', 1);

			this.is_show_app_tips = false;

		},
		Register() {
			this.nav_to('/pages/start/start2')
		},
		toFiltrate() {
			this.nav_to('/pages/friend/filtrate')
		},

		// 获取定位
		getLocationSysc() {
			let _this = this;
			return new Promise((resolve, reject) => {
				uni.getLocation({
					type: 'gcj02',
					success: function (res) {
						resolve(res)
					},
					fail: function (err) {
						const defaultLocation = {
							latitude: 0,
							longitude: 0
						};
						resolve(defaultLocation);
					}
				});
			})

		},

		async getCity() {
			try {
				let loc = await this.getLocationSysc();
				this.longitude = loc.longitude;
				this.latitude = loc.latitude;
			} catch (err) {
				this.longitude = err.longitude;
				this.latitude = err.latitude;
			}

		},
		async getAd() {

			let res = await this.$api.post('/banner/getbanner', {
				PageKey: '测试广告'
			});

			console.log('ad===' + JSON.stringify(res.data))

			if (res.data.length > 0) {

				this.ad_detail = res.data[0];
				this.$refs['banner_ad'].open();
			}

		},

		async getMemberNum() {
			let res = await this.$api.post('/Member/TotalNum')
			const last_count = res.data;

			return last_count;
		},
		go_ad_url(url) {
			this.$refs['banner_ad'].close();

			this.nav_to(url);
		},
		//下拉刷新
		async onRefresh() {
			this.PageIndex = 1;
			this.getMsgNum();
			if (await this.getList()) {
				uni.$emit('triggered');
			} else {
				setTimeout(() => {
					uni.$emit('triggered');
				}, 2000)
			}
		},
		//滚动到底部触发
		async scrolltolower() {
			this.PageIndex++;
			this.getMsgNum();
			this.getList();

		},
		celSearch() {
			this.showSearch = false;
			this.Name = "";
			this.search();
		},

		async getMsgNum() {
			const groupID = '#AW1o76PXU'
			const noID = uni.getStorageSync('user').UserID

		},
		async save_user_clientdata() {
			let c_model = '';
			let c_system = ''
			uni.getSystemInfo({
				success(res) {
					c_model = res.model;
					c_system = res.system;
				}
			});
			//在线用户
			await this.$api.post('User/UserOnline', {
				ClientModel: c_model,
				ClientOS: c_system
			});

		},
		async search() {
			//搜索
			this.PageIndex = 1;
			this.list = [];

			this.getList()
		},
		async getList() {
			let url;
			let reqDate;
			let UserActiveStatus = ""
			if (this.tabInd == 1) {
				url = 'Member/PageList';
				UserActiveStatus = "活跃"
				reqDate = {
					PageIndex: this.PageIndex,
					PageSize: this.PageSize,
					TrueName: this.Name,
					Sex: this.Sex,
					UserType: this.UserType,
					City: this.City,
					Last_Lat: this.latitude,
					Last_Lng: this.longitude,
					UserActiveStatus: UserActiveStatus,
					Tag: this.tagtext=='全部' ? '' : this.tagtext,
				}
				uni.setStorageSync('sportType', this.tagtext);
			} else if (this.tabInd == 2) {
				url = '/Member/Recommend';
				reqDate = {
					PageIndex: this.PageIndex,
					PageSize: this.PageSize,
					TrueName: this.Name,
					CompanyID: 6002,
					Sex: this.Sex,
					UserType: this.UserType,
					City: this.City,
					Last_Lat: this.latitude,
					Last_Lng: this.longitude,
					Tag: this.tagtext=='全部' ? '' : this.tagtext,
				}
			} else if (this.tabInd == 3) {
				url = '/Member/NearBy';
				UserActiveStatus = "附近";
				reqDate = {
					PageIndex: this.PageIndex,
					PageSize: this.PageSize,
					TrueName: this.Name,
					CompanyID: 6002,
					Sex: this.Sex,
					UserType: this.UserType,
					City: this.City,
					Last_Lat: this.latitude,
					Last_Lng: this.longitude,
					Tag: this.tagtext=='全部' ? '' : this.tagtext,
				}

			} else {
				url = 'Member/PageList';
				UserActiveStatus = "新人"
				reqDate = {
					PageIndex: this.PageIndex,
					PageSize: this.PageSize,
					TrueName: this.Name,
					CompanyID: 6002,
					Sex: this.Sex,
					UserType: this.UserType,
					City: this.City,
					Last_Lat: this.latitude,
					Last_Lng: this.longitude,
					UserActiveStatus: UserActiveStatus,
					Tag: this.tagtext=='全部' ? '' : this.tagtext,
				}

				// 更新本地存储，将latestCount保存为新的lastCount

				uni.setStorageSync('usersCount', this.toatalUserCount);

				this.newUserCount = 0;

			}

			let res = await this.$api.post(url, reqDate)


			if (res.data) {

				let gift = await this.$api.post('/Member/AcceptGiftReports', {
					PageIndex: 1,
					PageSize: 10000,
					Last_Lat: 0,
					Last_Lng: 0,
				})
				//消费榜
				let com = await this.$api.post('/Member/SendGiftReports', {
					PageIndex: 1,
					PageSize: 10000,
					Last_Lat: 0,
					Last_Lng: 0,
				})

				try {
					//循环查询用户的人气榜，如果该用户同时 人气榜和消费榜都有名，优先显示 人气榜
					res.data.forEach((item, index) => {
						let sq = gift.data.findIndex((s) => s.ID == item.ID);
						if (sq >= 0) {
							item.PopSeq = sq + 1; //索引+1
							item.SeqStr = '人气榜第'
						} else {
							sq = com.data.findIndex((s) => s.ID == item.ID);
							if (sq > 0) {
								item.PopSeq = sq + 1; //索引+1
								item.SeqStr = '月消费第'
							} else {
								item.PopSeq = 0;
							}
						}
					});

				} catch (e) {
					//TODO handle the exception
				}

				if (this.PageIndex == 1) {
					this.list = res.data
				} else {
					let list = this.list.concat(res.data)
					this.list = this.clearRepetition(list, "ID");
				}
				this.list.forEach(item=>{
					if(item.Tag && !Array.isArray(item.Tag)){
						item.Tag = item.Tag.split(',')
					}
				})
				this.load = true;

			}
		},
		// 去重
		clearRepetition(arr, key = "id") {
			let newArr = [];
			arr.forEach(item => {
				let index;
				let check = newArr.every((newItem, i) => {
					if (item[key] !== newItem[key]) {
						index = -1;
						return true;
					} else {
						index = i;

						return false;
					}
				})
				if (check) {
					newArr.push(item);
				} else {
					newArr.splice(index, 1, item);
				}

			})

			return newArr;
		},
		async init() {
			this.user = uni.getStorageSync('user');

			this.PageIndex = 1;

			await this.get_poplist();

			await this.getList();


			await this.$api.post('/Common/Add_ViewPath', {
				Path: 'assistant',
				Platform: uni.getStorageSync('platform')
			});

			await this.save_user_clientdata();

			this.getIsExpiredUser();
			let res = await this.$api.post('Coupon/List', {
				CompanyID: 6003
			})
			this.couponlist = res.data

		},
		scroll(e) {
			const detail = e.detail;
			this.calcExposure(detail.scrollTop)
		},
		calcExposure(scrollTop) {

			const height = uni.upx2px(542) //list高度

			const range = [Math.ceil(scrollTop / height), Math.floor((this.scroll_height + scrollTop) / height -
				1)] //获取从0排开始曝光序号区间
			if (this._range) {
				for (let i = this._range[0]; i <= this._range[1]; i++) {
					if (i < range[0] || i > range[1]) {
						clearTimeout(this['_st_' + i])
					}
				}
			}
			for (let i = range[0]; i <= range[1]; i++) {
				if (!this._range || i < this._range[0] || i > this._range[1]) {
					this['_st_' + i] = setTimeout(() => {
						if (!this.exposure_arr.has(i)) {
							this.exposure_arr.add(i)
							if (i * 2 > this.list.length - 1) {
								return;
							}
							const ids = [this.list[i * 2].ID, this.list[i * 2 + 1].ID]
							this.$api.post('/Common/UserExposure', {
								E_UserIDStr: ids.join(',')
							});

						}
					}, 800) //曝光时间设置
				}
			}

			this._range = range;
		},
		async get_poplist() {
			let res = await this.$api.post('/Member/AcceptGiftReports', {
				PageIndex: 1,
				PageSize: 5,
				Last_Lat: 0,
				Last_Lng: 0,
			})
			this.pop_list = res.data
		},
		async reLoad() {
			this.isreceive = uni.getStorageSync('isreceive')
			this.ossPath = this.$ossPath;
			let that = this;
			uni.$on('getFiltrate', function (data) {
				if (data) {
					that.City = data.city || ''
					that.Sex = data.sex || ''
				}
			})

			if (uni.getStorageSync('show_member_tips')) {
				if (uni.getStorageSync('show_member_tips') == 1)
					this.is_show_app_tips = false;
				else
					this.is_show_app_tips = true;

			} else {
				this.is_show_app_tips = true;
			}

			// #ifdef MP-WEIXIN
			uni.showShareMenu({
				withShareTicket: false,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			// #endif

			if (await this.$store.getters.getLoginState) {
				await this.getCity();

				if (uni.getStorageSync('Sex')) {
					this.Sex = uni.getStorageSync('Sex');
				}

				await this.init();

				await this.getAd();

				uni.$on('scroll_height', res => {
					this.scroll_height = res;
					this.calcExposure(0)
				});

				this.saveCid()
			}
			this.stCompanyID = uni.getStorageSync('CompanyID') || 6007
		},

	},
	


}
</script>

<style lang="scss">
.assistant {
	position: relative;
	height: 100vh;
	overflow: hidden;
}
.add_btn {
	position: fixed;
	right: 32rpx;
	bottom: 170rpx;
	width: 108rpx;
	height: 108rpx;
	z-index: 999;
	text-align: center;
	align-items: center;
	background: #0d0d0d;
	color: #fff;
	// line-height: 96rpx;
	border-radius: 100rpx;
	font-size: 22rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;

}
.registerbox {
	width: 90%;
	height: 128rpx;
	background-color: #000000;
	opacity: 0.8;
	border-radius: 24rpx;
	// margin: ;
	position: absolute;
	bottom: 5%;
	left: 4%;
	display: flex;
	align-items: center;

	.regimg {
		width: 72rpx;
		height: 72rpx;
		margin: 0 16rpx 0 24rpx;
		border-radius: 50%;
	}

	.regtitle_1 {
		font-size: 28rpx;
		font-weight: 600;
		color: #fff;
		margin-bottom: 10rpx;
	}

	.regtitle_2 {
		font-size: 24rpx;
		color: #fff;
		opacity: 0.6;
	}

	.regbtn {
		width: 188rpx;
		height: 60rpx;
		border-radius: 32rpx;
		background: linear-gradient(180deg, #FEF0BC 0%, #B98B51 100%);
		font-size: 28rpx;
		color: #4C310C;
		text-align: center;
		line-height: 60rpx;
		margin-left: 56rpx;
	}
}

.couponbox {
	position: absolute;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
	background: rgba(0, 0, 0, 0.5);
	z-index: 100;

	.titleh1 {
		width: 508rpx;
		height: 84rpx;
		margin-left: 70rpx;
		margin-bottom: 32rpx;
	}

	.coupon {
		position: relative;
		width: 576rpx;
		height: 548rpx;
		background-image: url('https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17128894802161316.png');
		background-repeat: no-repeat;
		background-size: cover;
		margin-left: 35rpx;

		.title1 {
			width: 288rpx;
			height: 56rpx;
			border-radius: 0, 0, 20rpx, 20rpx;
			background: linear-gradient(180deg, #FFEBD4 0%, #FFE0AC 100%);
			text-align: center;
			line-height: 56rpx;
			font-size: 32rpx;
			font-weight: 600;
			color: #3B1E06;
			margin: 0 auto;
			margin-bottom: 36rpx;
		}

		.conbox {
			position: relative;
			background-image: url('https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17128895073561466.png');
			background-repeat: no-repeat;
			background-size: cover;
			width: 496rpx;
			height: 120rpx;
			display: flex;
			align-items: center;
			margin: 0 auto;
			margin-bottom: 20rpx;

			.conimg {
				width: 96rpx;
				height: 96rpx;
			}

			.contitle_1 {
				font-size: 28rpx;
				font-weight: 600;
				color: #67370D;
			}

			.contitle_2 {
				font-size: 20rpx;
				color: #946032;
			}

			.numbox {
				position: absolute;
				right: 0;
				top: 0;
				background-image: url('https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/17128897267561216.png');
				background-repeat: no-repeat;
				background-size: cover;
				width: 64rpx;
				height: 32rpx;
				font-size: 20rpx;
				font-weight: 600;
				color: #fff;
				text-align: center;
				line-height: 26rpx;
			}
		}

		.nicebtn {
			width: 368rpx;
			height: 88rpx;
			position: absolute;
			bottom: 30rpx;
			left: 100rpx;
			border-radius: 47rpx;
			// margin: 0 auto;
			// margin-top: 54rpx;
			background: linear-gradient(90deg, #FEDCA1 0%, #FEC76D 100%);
			text-align: center;
			line-height: 88rpx;
			font-size: 32rpx;
			font-weight: 600;
			color: #3B1E06;
		}
	}

	.closeimg {
		width: 60rpx;
		height: 60rpx;
		margin-top: 40rpx;
		margin-left: 298rpx;
	}
}


.fix {
	position: fixed;
	width: 750rpx;
	top: 0;
	left: 0;
	z-index: 98;
	background-color: #fff;
}

.logo {
	box-sizing: border-box;
	height: 44px;
	width: 750rpx;
	background: #ffffff;
	display: flex;
	align-items: center;

	>image {
		width: 400rpx;
		margin-left: 24rpx;
	}
}

.tagbox {
	display: flex;
	align-items: center;
	justify-content: space-evenly;
	width: 490rpx;
	overflow-x: auto;
}

.tabs {
	box-sizing: border-box;
	z-index: 98;
	height: 44px;
	width: 750rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: #ffffff;
	white-space: nowrap;
	// border-bottom: 2rpx solid #eee;
	padding-bottom: 4rpx;
	.tab1,
	.tab2,
	.tab3 {
		font-size: 36rpx;
		margin-right: 45rpx;
		line-height: 44px;
		display: flex;
		font-weight: 700;
		color: #999999;
		
	}
	.tab_horn{
		position: relative;
		.horn_mark{
			position: absolute;
			top: 16rpx;
			right: -26rpx;
			min-width: 30rpx;
			height: 30rpx;
			padding: 0 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #dd524d;
			color: #fff;
			font-size: 22rpx !important;
			border-radius: 100rpx;
		}
		.num10{
			right: -36rpx;
		}
		.num99{
			right: -48rpx;
		}
	}

	.tab5 {
		font-size: 32rpx;
		line-height: 44px;
		height: 44px;
		// margin-right: 55rpx;
		color: #fff;
	}

	.tab4 {
		color: #333333;
		position: relative;
		font-size: 40rpx;

		&::before {
			position: absolute;
			left: 50%;
			transform: translate(-50%, -50%);
			bottom: 0;
			display: block;
			content: "";
			width: 34rpx;
			height: 10rpx;
			background: #333333;
			border-radius: 300rem;
		}
	}

	.checkbox {
		position: relative;
		display: flex;
		color: #666;
		font-size: 26rpx;
		padding: 6rpx 14rpx;
		padding-right: 36rpx;
		border-radius: 8rpx;
		background-color: #f5f5f5;

		&::after {
			position: absolute;
			top: 76%;
			right: -4rpx;
			transform: translate(-50%, -50%) rotate(135deg);
			content: '';
			border-top: 12rpx solid transparent;
			border-left: 12rpx solid transparent;
			border-right: 12rpx solid transparent;
			border-bottom: 12rpx solid #999;
		}
	}
}

.tabssearch {
	display: flex;
	align-items: center;
	height: 50px;
	width: 75%;
	box-sizing: border-box;
}

.user_status_box {
	line-height: 50rpx;
	text-align: center;
	height: 72rpx;

	.item {

		height: 72rpx;
		line-height: 72rpx;
		background-color: #FEEECD;



		text {
			font-size: 28rpx;
			color: #B6722E;
			text-decoration: underline;
		}

		.close {
			width: 36rpx;
			height: 36rpx;
			font-size: 20rpx;
			color: #F3B065;
			background-color: rgba(255, 255, 255, 0.6);
			display: flex;
			align-items: center;
			justify-content: center;
			right: 26rpx;
			top: 20rpx;
			position: absolute;
		}
	}
}

.message_box {

	line-height: 64rpx;
	text-align: center;
	height: 64rpx;
	padding: 25rpx 0 15rpx 0;

	.item {
		text-align: center;
		width: 40%;
		border: 2px solid rgba(253, 249, 246, 0.4);
		border-radius: 12px;
		background-color: #E1C4A6;
		margin: 0 auto;
		font-weight: bold;
		color: #111111;
	}
}



.list {
	padding-left: 26rpx;
	padding-right: 26rpx;
	padding-bottom: 60rpx;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	background-color: #f6f6f6;
	.item {
		margin-top: 20rpx;
		width: 340rpx;
		// height: 450rpx;
		border-radius: 8rpx;
		overflow: hidden;
		background: #fff;
		box-shadow: 0 0 6rpx #eee;

		.top {
			position: relative;
			// height: 450rpx;
			width: 340rpx;

			.tagbox {
				position: absolute;
				left: 0;
				top: 0;
				width: 80rpx;
				height: 40rpx;
				// border-radius: 0rpx 16rpx 0rpx 16rpx;
				z-index: 1000;

				.tagcolor {
					text-align: center;

					line-height: 40rpx;
					width: 100%;
					height: 100%;
					font-size: 20rpx;
					border-radius: 0 0 20rpx 0;

					color: black;
					background: linear-gradient(90deg, #C79F67 0%, #ECD5A0 100%);
				}

				.tagcolor2 {
					text-align: center;
					line-height: 40rpx;
					font-size: 20rpx;
					width: 100%;
					height: 100%;
					color: #fff;

					background: #012BAA;
					border-radius: 0rpx 0rpx 16rpx 0rpx;
				}
			}

			.imgbox {
				position: relative;
				z-index: 1;
				height: 450rpx;
				width: 340rpx;

				image {
					height: 100%;
					width: 100%;
				}

			}
			.uinfo_body{
				background-color: #fff;
				padding: 20rpx 14rpx;
				.uinfo_cell{
					display: flex;
					align-items: center;
					.uinfo_head{
						width: 48rpx;
						height: 48rpx;
						margin-right: 12rpx;
						border-radius: 50%;
						overflow: hidden;
						image{
							width: 100%;
							height: 100%;
						}
					}
					.uinfo_box{
						.box_tit{
							display: flex;
							align-items: center;
							.tit_name{
								font-size: 24rpx;
								color: #666666;
								max-width: 150rpx;
								max-width: 94rpx;
								overflow: hidden;  /*超出部分隐藏*/
								white-space: nowrap;  /*禁止换行*/
								text-overflow: ellipsis; /*省略号*/

								margin-right: 8rpx;
							}
							.tag_teacher{
								width: 68rpx;
								height: 32rpx;
								display: flex;
								align-items: center;
								justify-content: center;
								font-size: 16rpx;
								color: #fff;
								background-color: #012baa;
								border-radius: 4rpx;
							}
							.member {
								min-width: 52rpx;
								height: 32rpx;
								background: linear-gradient(135deg, #7E7E7E 0%, #292929 100%);
								border-radius: 2rpx;
								border: 2rpx solid #D6C6AB;
								text-align: center;
								color: #fff;
								font-size: 16rpx;
								line-height: 32rpx;
								margin-right: 8rpx;
							}
							
							.number_huan {
								color: #4C310C;
								background: linear-gradient(180deg, #FDF9F6 0%, #E1C4A6 100%);
								border: 2rpx solid #E6CEB5;
							}
							
							.member_wealth {
								width: 45rpx;
								height: 32rpx;
								background: linear-gradient(135deg, #deb214 0%, #f88410 100%);
								border-radius: 2rpx;
								border: 2rpx solid #D6C6AB;
								text-align: center;
								color: #fff;
								font-size: 16rpx;
								line-height: 32rpx;
								margin-left: 5rpx;
							}
						}
						.box_lit{
							margin-top: 4rpx;
							font-size: 20rpx;
							color: #999999;
							text{
								font-size: 20rpx;
								color: #999999;
								margin-right: 8rpx;
								&:last-child{
									margin-right: 0;
								}
							}
						}
					}
				}
			}

			.online {
				position: absolute;
				z-index: 10;
				top: 12rpx;
				right: 12rpx;
				color: #FFFFFF;
				font-size: 22rpx;

				&::before {
					display: inline-block;
					content: "";
					height: 16rpx;
					width: 16rpx;
					border-radius: 16rpx;
					background: #27BA2C;
					margin-right: 6rpx;
				}
			}

			.pop {
				box-sizing: border-box;
				position: absolute;
				z-index: 10;
				bottom: 140rpx;
				left: 7rpx;
				width: 220rpx;
				font-size: 24rpx;
				font-weight: bold;
				line-height: 40rpx;
				padding-left: 10rpx;
				color: #fff;

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}
			.tag_body{
				position: absolute;
				top: 10rpx;
				left: 10rpx;
				display: flex;
				flex-wrap: wrap;
				width: 210rpx;
				.tag_cell{
					padding: 6rpx 8rpx;
					color: #fff;
					font-size: 18rpx;
					font-weight: bold;
					margin-right: 4rpx;
					margin-bottom: 10rpx;
					background: rgba(0, 0, 0, 0.4);
					border-radius: 20rpx;
				}
			}
			.top_bottom {
				box-sizing: border-box;
				position: absolute;
				z-index: 10;
				bottom: 0;
				left: 0;
				width: 340rpx;
				// height: 145rpx;
				// background: linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%);
				align-items: center;
				padding: 10rpx 12rpx;
				
				.memberInfo {
					display: flex;
					align-items: center;

					.name {
						padding-left: 10rpx;
						max-width: 200rpx;
						height: 45rpx;
						font-size: 40rpx;
						line-height: 42rpx;
						color: #fff;
						padding-right: 16rpx;
						display: flex;
						align-items: center;
					}

					.member {
						min-width: 52rpx;
						height: 32rpx;
						background: linear-gradient(135deg, #7E7E7E 0%, #292929 100%);
						border-radius: 2rpx;
						border: 2rpx solid #D6C6AB;
						text-align: center;
						color: #fff;
						font-size: 16rpx;
						line-height: 32rpx;
					}

					.number_huan {
						color: #4C310C;
						background: linear-gradient(180deg, #FDF9F6 0%, #E1C4A6 100%);
						border: 2rpx solid #E6CEB5;
					}

					.member_wealth {
						width: 45rpx;
						height: 32rpx;
						background: linear-gradient(135deg, #deb214 0%, #f88410 100%);
						border-radius: 2rpx;
						border: 2rpx solid #D6C6AB;
						text-align: center;
						color: #fff;
						font-size: 16rpx;
						line-height: 32rpx;
						margin-left: 5rpx;
					}
				}

			}
		}

		.memberInfo2 {
			.bottom_info {
				margin-top: 12rpx;
				line-height: 36rpx;
				padding-left: 10rpx;

				text {
					margin-right: 8rpx;
					font-size: 24rpx;
					color: #fff;
				}
			}

			.flx {
				// padding-right: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.wx {
				display: flex;
				align-items: center;
				height: 40rpx;
				line-height: 40rpx;
				margin-left: -6rpx;
				text {
					margin-left: 8rpx;
					font-size: 24rpx;
					color: #ffffff;
				}
			}

			.distance {
				display: flex;
				align-items: center;
				.icon{
					
				}
				image {
					height: 24rpx;
					width: 24rpx;
				}

				text {
					font-size: 20rpx;
					// margin-left: 8rpx;
					color: #fff;
				}
			}
		}
	}
}


.ad-popup {
	background-color: #000;
	box-shadow: 0 0 15px #e7c91b;
	min-width: 550rpx;
	min-height: 500rpx;


	.popup-title {

		text-align: center;
		position: relative;
		color: #ffffff;
		font-weight: bold;

		.popup-close {
			font-size: 24rpx;
			position: absolute;
			right: 20rpx;
			top: 15rpx;
			color: #ffffff;
		}
	}

	image {
		width: 100%;
		height: 100%;
	}

	.down-close {
		width: 100%;
		text-align: center;
		align-items: center;
	}
}


.member-popup {

	background-image: url('https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1711089583152299.png');
	background-repeat: no-repeat;
	background-size: cover;

	min-width: 550rpx;
	min-height: 500rpx;
	padding: 10rpx 10rpx 20rpx 20rpx;

	.popup-title {
		padding: 20rpx 0 10rpx;
		text-align: center;
		position: relative;
		color: #3D210A;
		font-weight: bold;
		font-size: 42rpx;

		.popup-close {
			font-size: 24rpx;
			position: absolute;
			right: 20rpx;
			top: 15rpx;
			color: #999898;
		}
	}

	.tips {
		width: 322rpx;
		height: 48rpx;
		border-radius: 24rpx;
		border: 1rpx solid #A6712B;
		color: #A6712B;
		margin-left: 134rpx;
		text-align: center;
	}

	.desc {
		color: #999;
		padding-left: 20rpx;
		text-align: left;
		padding-top: 20rpx;

		.txtbox {
			display: flex;
			justify-content: space-around;

			.conbox {
				.conimg {
					width: 92rpx;
					height: 92rpx;
					margin-bottom: 10rpx;
				}

				.context {
					color: #333333;
					font-size: 28rpx;
				}
			}
		}

		.title {
			font-size: 28rpx;
			line-height: 66rpx;
			height: 66rpx;
			color: #3D210A;
		}

		.txt {
			color: #999;
			font-size: 32rpx;
			height: 50rpx;
		}
	}

	image {
		width: 100%;
		height: 100%;
	}

	.down-close {
		width: 100%;
		text-align: center;
		align-items: center;
	}

	.pop_btn {
		padding: 30rpx 50rpx 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		.btn-upgrade {
			width: 512rpx;
			height: 80rpx;
			background: #0D0D0D;
			color: #F7E0B2;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 50rpx;
			margin-bottom: 20rpx;
		}


	}
}
.tab_body{
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	padding: 20rpx 28rpx;
	padding-bottom: 0;
	padding-right: 0;
	.tab_cell{
		display: flex;
		align-items: center;
		margin-right: 16rpx;
		margin-bottom: 16rpx;
		padding: 8rpx 24rpx;
		// border: 2rpx solid #999;
		background-color: #f6f6f6;
		border-radius: 50rpx;
		&:nth-child(5n){
			// margin-right: 0;
		}
		.icon{
			width: 40rpx;
			height: 40rpx;
			margin-right: 8rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.tab_tit{
			font-size: 28rpx;
			font-weight: bold;
			color: #999;
		}
		
	}
	.tab_active{
			background-color: #706eee;
			// border-color: #706eee;
			
		.tab_tit{
			color: #fff;
		}
	}
}
</style>